package org.jeecg.modules.exTenderAnnQuaInqueryAnn.service.impl;

import org.jeecg.modules.exTenderAnnQuaInqueryAnn.entity.ExChangeResultAnno;
import org.jeecg.modules.exTenderAnnQuaInqueryAnn.entity.ExGcChangebulletinSection;
import org.jeecg.modules.exTenderAnnQuaInqueryAnn.mapper.ExGcChangebulletinSectionMapper;
import org.jeecg.modules.exTenderAnnQuaInqueryAnn.mapper.ExChangeResultAnnoMapper;
import org.jeecg.modules.exTenderAnnQuaInqueryAnn.service.IExChangeResultAnnoService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Collection;

/**
 * @Description: 招标公告（变更）
 * @Author: jeecg-boot
 * @Date:   2024-11-27
 * @Version: V1.0
 */
@Service
public class ExChangeResultAnnoServiceImpl extends ServiceImpl<ExChangeResultAnnoMapper, ExChangeResultAnno> implements IExChangeResultAnnoService {

	@Autowired
	private ExChangeResultAnnoMapper exChangeResultAnnoMapper;
	@Autowired
	private ExGcChangebulletinSectionMapper exGcChangebulletinSectionMapper;
	
	@Override
	@Transactional(rollbackFor = Exception.class)
	public void saveMain(ExChangeResultAnno exChangeResultAnno, List<ExGcChangebulletinSection> exGcChangebulletinSectionList) {
		exChangeResultAnnoMapper.insert(exChangeResultAnno);
		if(exGcChangebulletinSectionList!=null && exGcChangebulletinSectionList.size()>0) {
			for(ExGcChangebulletinSection entity:exGcChangebulletinSectionList) {
				//外键设置
				entity.setNoticeId(exChangeResultAnno.getId());
				exGcChangebulletinSectionMapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void updateMain(ExChangeResultAnno exChangeResultAnno,List<ExGcChangebulletinSection> exGcChangebulletinSectionList) {
		exChangeResultAnnoMapper.updateById(exChangeResultAnno);
		
		//1.先删除子表数据
		exGcChangebulletinSectionMapper.deleteByMainId(exChangeResultAnno.getId());
		
		//2.子表数据重新插入
		if(exGcChangebulletinSectionList!=null && exGcChangebulletinSectionList.size()>0) {
			for(ExGcChangebulletinSection entity:exGcChangebulletinSectionList) {
				//外键设置
				entity.setNoticeId(exChangeResultAnno.getId());
				exGcChangebulletinSectionMapper.insert(entity);
			}
		}
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delMain(String id) {
		exGcChangebulletinSectionMapper.deleteByMainId(id);
		exChangeResultAnnoMapper.deleteById(id);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void delBatchMain(Collection<? extends Serializable> idList) {
		for(Serializable id:idList) {
			exGcChangebulletinSectionMapper.deleteByMainId(id.toString());
			exChangeResultAnnoMapper.deleteById(id);
		}
	}
	
}
